Linux grep return code

您所在的位置:网站首页 Linux grep -e命令详解 Linux grep return code

Linux grep return code

2024-07-12 07:52| 来源: 网络整理| 查看: 265

The exit code is 1 because nothing was matched by grep.

EXIT STATUS The exit status is 0 if selected lines are found, and 1 if not found. If an error occurred the exit status is 2. (Note: POSIX error handling code should check for '2' or greater.)

The output is zero because the count of 'Total' is zero. This due to the -c option:

-c, --count Suppress normal output; instead print a count of matching lines for each input file. With the -v, --invert-match option (see below), count non-matching lines. (-c is specified by POSIX.)

If you would like to force an exit code of 0, you can just append || true to your command:

echo 'Total' | grep -c No || true


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3